package cn.wolfcode.service.impl;

import cn.wolfcode.domain.ClassInfo;
import cn.wolfcode.mapper.ClassInfoMapper;
import cn.wolfcode.qo.ClassInfoQueryObject;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IClassInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassInfoServiceImpl implements IClassInfoService{
    @Autowired
    private ClassInfoMapper classInfoMapper;
    @Override
    public void delete(Long id) {
        classInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void save(ClassInfo classInfo) {
        classInfoMapper.insert(classInfo);
    }

    @Override
    public ClassInfo select(Long id) {
        return classInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ClassInfo> listAll() {
        return classInfoMapper.selectAll();
    }

    @Override
    public void update(ClassInfo classInfo) {
        classInfoMapper.updateByPrimaryKey(classInfo);
    }

    @Override
    public PageInfo<ClassInfo> query(ClassInfoQueryObject qo) {
        //传入当前页和每页显示的数量
        //调用startPage方法后会对下一句sql 进行拦截,并改造为分页的sql
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<ClassInfo> classInfos = classInfoMapper.selectForList(qo);
        return new PageInfo<>(classInfos);
    }

}
